package com.qf.swagger.controller;

import com.qf.swagger.entity.User;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
@Api(tags = "用户管理模块")

public class UsserController {
    @RequestMapping(value = "/test1",method = RequestMethod.GET)
    public String test1(){
        System.out.println("test1....");
        return "hello swagger";
    }
    @RequestMapping(value = "/test2",method = RequestMethod.POST)
    public User test2(){
        System.out.println("getUser....");
        User user = new User();
        user.setName("jack");
        user.setPassword("123");
        return user;
    }
    @GetMapping("/getUser/{id}")
    public User findById(@PathVariable(value = "id") Integer id) {
        User user = new User();
        user.setId(1);
        user.setPassword("123");
        user.setName("张三");
        user.setRegistTime(new Date());
        user.setBirthday(new Date());
        user.setSex("1");
        return user;
    }
    @GetMapping("/getUserByname")
    public User findByName(String username,Integer age) {
        System.out.println(username);
        User user = new User();
        user.setId(1);
        user.setPassword("123");
        user.setName("张三");
        user.setRegistTime(new Date());
        user.setBirthday(new Date());
        user.setSex("1");
        return user;
    }
    /**
     * 添加新用户
     * @param user
     */
    @PostMapping("/add")
    public User addUser(@RequestBody User user) {
        System.out.println("====" + user);
        System.out.println("=====添加用户成功=====");
        return user;
    }
    /**
     * 查询所有用户数据返回
     */
    @GetMapping("/findAll")
    public List<User> findUserAll() {
        //1. 创建用户集合对象
        List<User> userList = new ArrayList<>();
        //2. 返回用户集合对象
        return userList;
    }
    /**
     * 根据用户主键id修改用户属性
     * @param user
     */
    @PutMapping("/edit")
    public User editUser(@RequestBody User user) {
        System.out.println("====" + user);
        System.out.println("=====修改用户成功=====");
        return user;
    }
    @RequestMapping(value = "/delusers",method = RequestMethod.POST)
    public Integer deleteUsers( Integer[] ids ){
        List<Integer> idList = Arrays.asList(ids);
        idList.forEach(System.out::println);
        System.out.println("=====删除用户成功=====");
        return 0 ;
    }
    /**
     * 根据id删除用户
     */
    @DeleteMapping("/del/{id}")
    public Long delbyId(@PathVariable(value = "id") Long id) {
        System.out.println("======删除用户成功=====");
        return id;
    }

}
